package com.spring.beans;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Asuka
 * @Description:
 * @create: 2025-04-13 17:26
 */


public class PropertyValues {

    private final List<PropertyValue> propertyValueList = new ArrayList<>();


    public void addPropertyValue(PropertyValue pv) {
        for (int i = 0;i<propertyValueList.size();i++){
            PropertyValue currenPv = this.propertyValueList.get(i);
            if (currenPv.getName().equals(pv.getName())) {
                //覆盖原有的属性值
                this.propertyValueList.set(i,pv);
                return;
            }
        }
        this.propertyValueList.add(pv);
    }

    public PropertyValue[] getPropertyValues() {
        return this.propertyValueList.toArray(new PropertyValue[0]);
    }

    public PropertyValue getPropertyValue(String propertyName) {
        for (PropertyValue propertyValue : this.propertyValueList) {
            if (propertyValue.getName().equals(propertyName)) {
                return propertyValue;
            }
        }

        return null;
    }
}
